package com.laguille.games.monopoly.commons.event;

import org.apache.commons.lang.Validate;

import com.laguille.games.monopoly.commons.player.Player;
import com.laguille.games.monopoly.commons.property.Property;

/**
 * This event is emitted when a player moves on the board.
 *
 */
public class PlayerMoveEvent extends Event {

	private final Player player;
	private final Property oldPosition;
	private final Property newPosition;
	
	public PlayerMoveEvent(Player player, Property oldPosition, Property newPosition) {
		Validate.notNull(player);
		Validate.notNull(oldPosition);
		Validate.notNull(newPosition);
		this.player = player;
		this.oldPosition = oldPosition;
		this.newPosition = newPosition;
	}

	public Player getPlayer() {
		return player;
	}

	public Property getOldPosition() {
		return oldPosition;
	}

	public Property getNewPosition() {
		return newPosition;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((newPosition == null) ? 0 : newPosition.hashCode());
		result = prime * result
				+ ((oldPosition == null) ? 0 : oldPosition.hashCode());
		result = prime * result + ((player == null) ? 0 : player.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PlayerMoveEvent other = (PlayerMoveEvent) obj;
		if (newPosition == null) {
			if (other.newPosition != null)
				return false;
		} else if (!newPosition.equals(other.newPosition))
			return false;
		if (oldPosition == null) {
			if (other.oldPosition != null)
				return false;
		} else if (!oldPosition.equals(other.oldPosition))
			return false;
		if (player == null) {
			if (other.player != null)
				return false;
		} else if (!player.equals(other.player))
			return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "PlayerMoveEvent [player=" + player + ", oldPosition="
				+ oldPosition + ", newPosition=" + newPosition + "]";
	}

}
